package com.xxx.bluetooth;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;


/**
 * A simple {@link Fragment} subclass.
 * @author hdz
 */
public class HomeFragment extends Fragment implements View.OnClickListener {

    private PageSwitchListener mListener;

    public HomeFragment() {
        // Required empty public constructor
    }

    public void setPageSwitchListener(PageSwitchListener listener) {
        mListener = listener;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_home, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Button enterClientPageBtn = (Button)getView().findViewById(R.id.enter_client_page_btn);
        enterClientPageBtn.setOnClickListener(this);
        Button enterServerPageBtn = (Button)getView().findViewById(R.id.enter_server_page_btn);
        enterServerPageBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.enter_client_page_btn) {
            if (mListener != null) {
                mListener.enterPage(1);
            }
        } else if (v.getId() == R.id.enter_server_page_btn) {
            if (mListener != null) {
                mListener.enterPage(2);
            }
        }
    }
}
